# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=loki-packet
pkgver=0.3.0_r502
pkgrel=3
pkgdesc='Python based framework implementing many packet generation and attack modules for Layer 2 and 3 protocols.'
arch=('x86_64' 'aarch64')
url='http://c0decafe.de/loki.html'
license=('BSD')
depends=('python2' 'pygtk' 'python2-ipy' 'python2-dpkt' 'python2-urwid'
         'python2-pylibpcap' 'libpcap' 'libdnet' 'libglade' 'openssl-1.0')
makedepends=('autoconf' 'automake' 'subversion' 'cython2')
source=("$pkgname::svn+http://c0decafe.de/svn/codename_loki/trunk")
sha512sums=('SKIP')
options=(!emptydirs)

pkgver() {
	cd $pkgname

	local ver="$(svnversion)"

  printf "0.3.0_r%s" "${ver//[[:alpha:]]}"
}

prepare() {
	cd $pkgname

	sed -i 's|#!/usr/bin/env python|#!/usr/bin/env python2|' src/loki_*.py
  grep -rl 'python-config' . | xargs sed -i 's|python-config|python2-config|g'

	for i in build.sh misc test pkg_scripts modules/module_test.py \
    modules/moodule_snmp.py modules/module_snmp.glade modules/module_802_1X.py \
    modules/module_802_1X.glade ; do
    rm -rf $i
	done
}

build() {
	cd $pkgname

  autoreconf -fvi -I m4

  ./configure --prefix=/usr PYTHON=/usr/bin/python2

  make
}

package() {
  cd $pkgname

	make DESTDIR="$pkgdir" install

  install -Dm 755 src/loki_urw.py "$pkgdir/usr/bin/loki-urw"
  install -Dm 755 src/loki_gtk.py "$pkgdir/usr/bin/loki-gtk"

  install -Dm 644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE COPYING
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" AUTHORS ChangeLog \
    README REQUIREMENTS
}

